const cors = require('cors');
const HyperExpress = require('hyper-express');
const webserver = new HyperExpress.Server();

webserver.use(cors());

// Create GET route to serve 'Hello World'
webserver.get('/abc', (request, response) => {
  response.sse.open();
  let num = 0;
  setInterval(()=>{
    num += 20
    response.sse.send(JSON.stringify({
      time:new Date().toLocaleString(),
      num,
    }));
  },2000)
})

webserver.listen(8080)
.then((socket) => console.log('http://127.0.0.1:8080'))
.catch((error) => console.log('Failed to start webserver on port 8080'));